home *** CD-ROM | disk | FTP | other *** search
/ Programming Sound Cards / Programming Sound Cards.iso / sound_20 / mfwrite_.c < prev    next >
C/C++ Source or Header  |  1995-01-01  |  1KB  |  52 lines

  1. /*
  2.  * writing_example.c 4/30/89
  3.  *
  4.  */
  5. #include <stdio.h>
  6. #include <ctype.h>
  7. #include "midifile.h"
  8.  
  9. /* These lines are needed to use the library */
  10. FILE *fp;
  11. myputc(c) { return(putc(c,fp));}
  12.  
  13.  
  14. /*
  15.  * mywritetrack()
  16.  *
  17.  * Sample showing how to use the library routines to write out a track.
  18.  * Returns 1 if successful, and -1 if not.  The track consists of
  19.  * a series of quarter notes from lowest to highest in pitch at
  20.  * constant velocity, each separted by a quarter-note rest.
  21.  *
  22.  */
  23. int mywritetrack(track)
  24. int track;
  25. {
  26.     int i;
  27.     char data[2];
  28.  
  29.     mf_write_tempo((long)500000); /* 120 beats/per/second */
  30.  
  31.     for(i = 1 ; i < 128; i++){
  32.        data[0] = i; /* note number */ 
  33.        data[1] = 64; /* velocity */ 
  34.        if(!mf_write_midi_event(480,note_on,1,data,2)) return(-1);
  35.        if(!mf_write_midi_event(480,note_off,1,data,2)) return(-1);
  36.     }
  37.     return(1);
  38. } /* end of write_track() */
  39.  
  40. main(argc,argv)
  41. char **argv;
  42. {
  43.     if((fp = fopen(argv[1],"w")) == 0L)
  44.     printf("f1to0: unable to open file %s for writing.\n",argv[1]);
  45.  
  46.     Mf_putc = myputc;
  47.     Mf_writetrack = mywritetrack;
  48.  
  49.     /* write a single track */
  50.     mfwrite(0,1,480,fp);
  51. }
  52.